package com.cloud.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @Author: TongRui乀
 * @Date: 2019/10/15 17:00
 * @description：
 */
@RequestMapping("test")
@RestController
public class WebController {


    @GetMapping("service")
    public String hello() {
        return "hi i am service 2-1";
    }


    @GetMapping("timeout")
    public String timeout(long timeout){

        try {
            Thread.sleep(timeout);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "SUCCESS";
    }


    @PostMapping("upload")
    public String upload(MultipartFile file) throws IOException {

        if(!file.isEmpty()){
            file.transferTo(new File("D:\\temp\\tmp\\temp.mp4"));
        }

        return "SUCCESS";
    }

    @GetMapping("error")
    public String error(){
        int a = 1 / 0;
        return "SUCCESS";
    }
}
